package com.medvalley.tcm.dao;

import com.medvalley.tcm.domain.YangShengSeaon;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface YangShengSeaonDao extends JpaRepository<YangShengSeaon, Long> {

    Page<YangShengSeaon> findAllByStatus(Pageable pageable, int status);

    @Query(nativeQuery = true, value = " SELECT   * FROM   t_yangsheng_season t1 WHERE t1.id >=  ((SELECT MAX(id)  FROM `t_yangsheng_season` where tag=:tag and status = 1) -  (SELECT  MIN(id)  FROM  t_yangsheng_season where tag = :tag and status = 1)) * RAND() +  (SELECT MIN(id) FROM  t_yangsheng_season where tag=:tag and status = 1) and status =1 and tag = :tag LIMIT :num")
    List<YangShengSeaon> findAllByRand(@Param("tag") int tag, @Param("num") int num);


    List<YangShengSeaon> findAllByIdIn(List<Long> ids);

}
